package com.bilibili.bilibili.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bilibili.bilibili.R;
import com.bilibili.bilibili.customview.CircleImageView;
import com.bilibili.bilibili.model.LiveModel;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * 作者：郭传沛 on 2017/3/10 20:17
 * 邮箱：bestyourselfgcp@163.com
 * 类用途:
 */

public class MyGridViewAdpter extends BaseAdapter {
    private Context mContext;
    private List<LiveModel.DataBean.PartitionsBean.LivesBean> mLivesBeen;

    public MyGridViewAdpter(Context context, List<LiveModel.DataBean.PartitionsBean.LivesBean> livesBeen) {
        mContext = context;
        mLivesBeen = livesBeen;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public Object getItem(int position) {
        return mLivesBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.gridview_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(mLivesBeen.get(position).getCover().getSrc()).into(viewHolder.item_live_cover);
        Glide.with(mContext).load(mLivesBeen.get(position).getOwner().getFace()).into(viewHolder.item_live_user_cover);
        viewHolder.item_live_title.setText(mLivesBeen.get(position).getTitle());
        viewHolder.item_live_user.setText(mLivesBeen.get(position).getOwner().getName());
        viewHolder.item_live_count.setText(mLivesBeen.get(position).getOnline() + "");
        return convertView;
    }


    public static class ViewHolder {
        public View rootView;
        public ImageView item_live_cover;
        public CircleImageView item_live_user_cover;
        public TextView item_live_title;
        public TextView item_live_user;
        public TextView item_live_count;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.item_live_cover = (ImageView) rootView.findViewById(R.id.item_live_cover);
            this.item_live_user_cover = (CircleImageView) rootView.findViewById(R.id.item_live_user_cover);
            this.item_live_title = (TextView) rootView.findViewById(R.id.item_live_title);
            this.item_live_user = (TextView) rootView.findViewById(R.id.item_live_user);
            this.item_live_count = (TextView) rootView.findViewById(R.id.item_live_count);
        }

    }
}
